//
//  FontEngine.m
//  ChinaBookingPhone
//
//  Created by 杨 锐 on 14-5-21.
//  Copyright (c) 2014年 xingheng. All rights reserved.
//

#import "FontHelper.h"

@implementation FontHelper

/**
 *  根据字符串固定高度计算宽度
 *
 *  @param strContent 字符串
 *  @param font       设置字体
 *  @param strHeight  高度
 *
 *  @return 返回宽度
 */
+(CGFloat)strReturnWidth:(NSString *)strContent font:(UIFont *)font strHeight:(CGFloat)strHeight{
    
    NSStringDrawingOptions option = NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
    NSDictionary *attribute = @{NSFontAttributeName:font};
    CGSize size = [strContent boundingRectWithSize:CGSizeMake(MAXFLOAT, strHeight)
                                           options:option
                                        attributes:attribute
                                           context:nil].size;
    return size.width;
}

/**
 *  根据字符串固定宽度计算高度
 *
 *  @param strContent 字符串
 *  @param font       设置字体
 *  @param strWidth   宽度
 *
 *  @return 返回高度
 */
+(CGFloat)strReturnHeight:(NSString *)strContent font:(UIFont *)font strWidth:(CGFloat)strWidth{
    
    NSStringDrawingOptions option = NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
    NSDictionary *attribute = @{NSFontAttributeName:font};
    CGSize size = [strContent boundingRectWithSize:CGSizeMake(strWidth, MAXFLOAT)
                                           options:option
                                        attributes:attribute
                                           context:nil].size;
    return size.height;
}

@end
